package com.cms.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cms.entity.Admin;
import com.cms.entity.User;

/**
*@author:gang
*@version:
**/
@Controller
@RequestMapping("/test")
public class JstlAction{
	

	private List<String> list;
	private String [] array ={"array1","array2","array3","array4"};
	private Date date;

	@RequestMapping("/jstltest")
	public String jstltest(HttpServletRequest request,ModelMap map){
		
        // 普通字符串
        request.setAttribute("hello", "hello world");
        
        //HTML字符串
        request.setAttribute("welcome", "<font color='red'>welcome</font>");
    
        //条件控制标签
        request.setAttribute("v1", 10);
        request.setAttribute("v2", 20);
		list = new LinkedList<String>();
		list.add("list1_1");
		list.add("list1_2");
        request.setAttribute("userList", list);
    
        //结构
            
        
        Admin admin = new Admin();
        admin.setAdminName("ant-black");
                
        List<User> users = new ArrayList<User>();
        for (int i=0; i<10; i++) {
                User user = new User();
                user.setUserName("aaa");
                user.setUserPassword("123456");
                user.setUid(i);
                user.setAdmin(admin);
                users.add(user);
        }
        request.setAttribute("users", users);
        
        
        //map
        Map<String, String> map001 = new HashMap<String, String>();
        map001.put("key1", "value1");
        map001.put("key2", "value2");
        map001.put("key3", "value3");
        map001.put("key4", "value4");
        request.setAttribute("map", map001);
        
        //array
        map.addAttribute("array", array);
        
        
        //对象
        date = new Date();
        map.addAttribute("date", date);
        
        
        //forTokens
        request.setAttribute("strTokens", "1#2#3#4#5");
        return "jstltest";
	}
}
	


